﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ScoreManager : System.Web.UI.Page
{
    private int perPage = 8;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData(0 * perPage, perPage);
            BtnLast.PostBackUrl = "?page=2";
            BtnNext.PostBackUrl = "?page=2";
            

        }
    }

    private void LoadData(int start, int num)
    {
        try
        {
            foreach (var data in ScoreDao.FindAll(start, num))
            {
                TableRow row = new TableRow();
                TableCell cellId = new TableCell();
                TableCell cellStudnetName = new TableCell();
                TableCell cellCourseName = new TableCell();
                TableCell cellScore = new TableCell();
                TableCell cellOperation = new TableCell();
                

                TextBox tb = new TextBox();
                TableCell cellGrade = new TableCell();
                cellGrade.Controls.Add(tb);
                cellId.Text = "" + data.Id;
                cellStudnetName.Text = data.StudentName;
                cellCourseName.Text = data.CourseName;
                cellScore.Text = data.Score;
                cellOperation.Text = "<a href=\"?action=edit&id=" + data.Id + "\">修改&nbsp" + "<a href=\"?action=delete&id=" + data.Id + "\">删除";

                row.Cells.Add(cellId);
                row.Cells.Add(cellStudnetName);
                row.Cells.Add(cellCourseName);
                row.Cells.Add(cellScore);
                row.Cells.Add(cellOperation);
                Table1.Rows.Add(row);
            }
        }
        catch (Exception)
        {

            throw;
        }
    }


    protected void BtnLast_Click(object sender, EventArgs e)
    {
        int page = Convert.ToInt32(Request.QueryString["page"]);
        LoadData((page - 1) * perPage, perPage);
        BtnLast.PostBackUrl = "?page=" + (page - 1);
    }

    protected void BtnNext_Click(object sender, EventArgs e)
    {
        int page = Convert.ToInt32(Request.QueryString["page"]);
        LoadData((page - 1) * perPage, perPage);
        BtnNext.PostBackUrl = "?page=" + (page + 1);
    }




    protected void BtnQuery_Click(object sender, EventArgs e)
    {
        string keyWord = TextBox1.Text;
        //CourseInfo data = CourseDao.Find(keyWord);

        foreach (var data in CourseDao.Find(keyWord))
        {
            TableRow row = new TableRow();
            TableCell cellId = new TableCell();
            TableCell cellCourseCode = new TableCell();
            TableCell cellCourseName = new TableCell();
            TableCell cellOperation = new TableCell();


            TextBox tb = new TextBox();
            TableCell cellGrade = new TableCell();
            cellGrade.Controls.Add(tb);
            cellId.Text = "" + data.Id;
            cellCourseCode.Text = data.CourseCode;
            cellCourseName.Text = data.CourseName;
            cellOperation.Text = "<a href=\"?action=edit&id=" + data.Id + "\">修改&nbsp" + "<a href=\"?action=delete&id=" + data.Id + "\">删除";

            row.Cells.Add(cellId);
            row.Cells.Add(cellCourseCode);
            row.Cells.Add(cellCourseName);
            row.Cells.Add(cellOperation);
            Table1.Rows.Add(row);
        }
    }
}